<<<<<<< HEAD
// pages/book/type/index.js
const $api = require("../../../api/book").API

Page({

  /**
   * 页面的初始数据
   */
  data: {
    recommendList:[],
    tabList:[],
    page:1,
    orderlist:[],
    orderindex:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var t = this
    t.setData({
      typekey:options.typekey
    })
    t.getBooksSearchType()

    console.log(options)
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var t = this
    // t.getBooksListByType()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var t = this
    t.setData({
      page:t.data.page + 1
    })
    t.getrecommendlist()

  },
  
  gotoalbum(e){
    var t = this
    console.log(e)
    wx.navigateTo({
      url:'/pages/book/album/index?id='+e.currentTarget.dataset.id+'&type='+e.currentTarget.dataset.type,
    })
  },
  // 获取书籍检索类型
  getBooksSearchType(){
    var t = this,
    data={
      dict_type:"BooksSearchType"
    }
    $api.getBooksSearchType(data).then(res=>{
      console.log(res)
      for(var i in res.data){
        var tabkey = i
        break;
      }
      t.setData({
        tabList:res.data,
        tabindex:tabkey
      })
      t.getBooksOrderType()
    })
  },
  choosetype(e){
    var t = this
    console.log(e)
    t.setData({
      tabindex:e.currentTarget.dataset.id,
      page:1,
      recommendList:[],
    })
    t.getrecommendlist()

  },
  getBooksOrderType(){
    var t = this,
    data = {
      dict_type:"BooksOrderType",
    }
    $api.getBooksOrderType(data).then(res=>{
      t.setData({
        orderlist:res.data
      })
      t.getrecommendlist()

    })
  },
  chooseorder(e){
    var t = this
    console.log(e)
    t.setData({
      orderindex:e.currentTarget.dataset.index,
      page:1,
      recommendList:[],
    })
    t.getrecommendlist()
  },
  // 获取听书推荐
  getrecommendlist(){
    var t = this,
    data = {
      booksRecommendType:1,
      pageNo:1,
      member_id:wx.getStorageSync('memberinfo').member_id,
      search_type:t.data.tabList[t.data.tabindex].dict_key,
      search_order:"",
      order_type:t.data.orderlist[t.data.orderindex].dict_key,
    }
    $api.getrecommendlist(data).then(res=>{
      var list = t.data.recommendList
      list = list.concat(res.data)
      t.setData({
        recommendList:list
      })
    })
  },
=======
// pages/book/type/index.js
const $api = require("../../../api/book").API

Page({

  /**
   * 页面的初始数据
   */
  data: {
    recommendList:[],
    tabList:[],
    page:1,
    orderlist:[],
    orderindex:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var t = this
    t.setData({
      typekey:options.typekey
    })
    t.getBooksSearchType()

    console.log(options)
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var t = this
    // t.getBooksListByType()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var t = this
    t.setData({
      page:t.data.page + 1
    })
    t.getrecommendlist()

  },
  
  gotoalbum(e){
    var t = this
    console.log(e)
    wx.navigateTo({
      url:'/pages/book/album/index?id='+e.currentTarget.dataset.id+'&type='+e.currentTarget.dataset.type,
    })
  },
  // 获取书籍检索类型
  getBooksSearchType(){
    var t = this,
    data={
      dict_type:"BooksSearchType"
    }
    $api.getBooksSearchType(data).then(res=>{
      console.log(res)
      for(var i in res.data){
        var tabkey = i
        break;
      }
      t.setData({
        tabList:res.data,
        tabindex:tabkey
      })
      t.getBooksOrderType()
    })
  },
  choosetype(e){
    var t = this
    console.log(e)
    t.setData({
      tabindex:e.currentTarget.dataset.id,
      page:1,
      recommendList:[],
    })
    t.getrecommendlist()

  },
  getBooksOrderType(){
    var t = this,
    data = {
      dict_type:"BooksOrderType",
    }
    $api.getBooksOrderType(data).then(res=>{
      t.setData({
        orderlist:res.data
      })
      t.getrecommendlist()

    })
  },
  chooseorder(e){
    var t = this
    console.log(e)
    t.setData({
      orderindex:e.currentTarget.dataset.index,
      page:1,
      recommendList:[],
    })
    t.getrecommendlist()
  },
  // 获取听书推荐
  getrecommendlist(){
    var t = this,
    data = {
      booksRecommendType:1,
      pageNo:1,
      member_id:wx.getStorageSync('memberinfo').member_id,
      search_type:t.data.tabList[t.data.tabindex].dict_key,
      search_order:"",
      order_type:t.data.orderlist[t.data.orderindex].dict_key,
    }
    $api.getrecommendlist(data).then(res=>{
      var list = t.data.recommendList
      list = list.concat(res.data)
      t.setData({
        recommendList:list
      })
    })
  },
>>>>>>> 1c9ce1fdc7fcbf1a028b999eb3cd07f698a8a329
})